package my.controller;

import my.controller.request.TestRequest;
import my.controller.response.TestResponse;
import my.database.test.entity.Test;
import my.database.test.repository.TestDao;
import my.service.DistrictService;
import my.service.TestService;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * controller invoke DTOGenerator and service.
 * @author xnat
 */
@RestController
@RequestMapping("rest")
public class TestRestController extends BaseController {

    @Resource
    TestService     testService;
    @Resource
    DistrictService districtService;
    @Resource
    TestDao         testDao;
    @Resource
    JpaProperties   jpaProperties;



    @GetMapping("json")
    TestResponse json(@RequestBody(required = false) TestRequest pRequest) {
        log.info("request: {0}", pRequest);
        TestResponse resp = new TestResponse();
        resp.setSuccess(true);
        resp.setState(null);
        resp.setStr2("str2");
        resp.setStr_1("str_1");
        log.debug("response: {0.class}, abcdac {0.str1}", resp);
        return resp;
    }

    // should be use actuator
    @GetMapping("test")
    Object test() {
        // return testDao.findAll();
        // return testProperties.getNestedProp();
        return jpaProperties;
    }
    @PostMapping("insert")
    void insert() {
        Test test = new Test();
        test.setLove("afa");
        test.setName("test");
        testDao.save(test);
    }
}
